<script setup lang="ts">
import {ref, watch} from 'vue'

const props = defineProps<{
  isEditorFullscreen?: boolean,
  referenceAnswer?: string,
  score?: number
}>()

// 综合题内容
const comprehensiveContent = ref('')
// 添加分值
const score = ref(0)

// 获取综合题答案，用于提交
const getReferenceAnswer = () => {
  return comprehensiveContent.value
}

// 获取分值
const getScore = () => {
  return score.value
}

// 初始化综合题数据
const initComprehensiveData = () => {
  if (props.referenceAnswer) {
    comprehensiveContent.value = props.referenceAnswer;
  }
  
  if (props.score !== undefined) {
    score.value = props.score;
  }
}

// 监听数据变化
watch([() => props.referenceAnswer, () => props.score], () => {
  initComprehensiveData();
}, { immediate: true });

// 暴露给父组件的方法
defineExpose({
  getReferenceAnswer,
  getScore
})
</script>

<template>
  <el-form-item
    prop="comprehensive"
    :class="{ 'hide-when-fullscreen': isEditorFullscreen }"
  >
    <div class="question-container">
      <div class="question-header">
        <div class="header-left">
          <h3 class="section-title">综合题选项<span class="required-asterisk">*</span></h3>
        </div>
      </div>

      <div class="comprehensive-wrapper">
        <div class="score-section">
          <div class="section-header">
            <span class="section-label">分值</span>
            <el-tag size="small" effect="plain" type="info">SCORE</el-tag>
          </div>
          <div class="score-input-wrapper">
            <el-input-number
                v-model="score"
                :min="0"
                :max="100"
                controls-position="right"
                placeholder="分值"
                class="score-input"
            />
          </div>
        </div>

        <span class="section-label">答案</span>
        <el-input
          v-model="comprehensiveContent"
          type="textarea"
          :rows="10"
          placeholder="请输入综合题答案"
          resize="none"
          class="comprehensive-input"
        />
      </div>
    </div>
  </el-form-item>
</template>

<style scoped>
.question-container {
  width: 100%;
  background: var(--el-bg-color);
  border-radius: 8px;
  padding: 20px;
  border: 1px solid var(--el-border-color);
  margin-bottom: 16px;
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  position: relative;
  padding-bottom: 8px;
}

.section-title::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 24px;
  height: 2px;
  background-color: var(--el-color-primary);
  border-radius: 1px;
}

.required-asterisk {
  color: var(--el-color-danger);
  margin-left: 4px;
}

.comprehensive-wrapper {
  position: relative;
}

/* 综合题样式 */
.comprehensive-input {
  width: 100%;
  margin-top: 20px;
}

.hide-when-fullscreen {
  display: none !important;
}

/* 添加分值样式 */
.score-section {
  width: 200px;
  margin-bottom: 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.section-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--el-text-color-primary);
  position: relative;
  padding-left: 10px;
}

.section-label::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 14px;
  background-color: var(--el-color-primary);
  border-radius: 1.5px;
}

.score-input-wrapper {
  display: flex;
  align-items: flex-start;
}

:deep(.score-input) {
  width: 100%;
}

:deep(.score-input .el-input-number__decrease),
:deep(.score-input .el-input-number__increase) {
  border-radius: 0;
}

:deep(.score-input .el-input__wrapper) {
  padding-right: 30px;
}
</style> 